package com.polaris.live.popup.base

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.annotation.CallSuper
import androidx.cardview.widget.CardView
import androidx.viewbinding.ViewBinding
import com.lxj.xpopup.core.BottomPopupView
import com.polaris.live.R
import com.polaris.live.common.ext.dp
import com.polaris.live.common.util.NavigationBarUtils
import com.polaris.live.common.util.ViewUtils

/**
 * BaseLiveBottomPopupView
 *
 * @author Created by lucas on 2023/11/2 20:06
 */
abstract class BaseLiveBottomPopupView<VB : ViewBinding>(
    context: Context,
    private val viewBindingFactory: (View) -> VB
) : BottomPopupView(context) {

    lateinit var mBinding: VB

    @CallSuper
    override fun onCreate() {
        super.onCreate()

        mBinding = viewBindingFactory.invoke(popupImplView)

        getCardView()?.also {
            ViewUtils.setCardViewBackground(
                it,
                getBackgroundColor(),
                topLeftCorner = 12.dp,
                topRightCorner = 12.dp
            )
        }
        val view = getContentView()
        val lp = view.layoutParams as ViewGroup.LayoutParams
        lp.height = NavigationBarUtils.getNavigationBarHeight(context)
        view.layoutParams = lp

    }

    open fun getCardView(): CardView? = null

    open fun getBackgroundColor(): Int = R.color.color_fa1d1928

    abstract fun getContentView(): View

}